/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipse.iota.model;

import java.lang.Boolean;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.iota.IotaPackage;

/**
 * @see org.eclipse.iota.IotaPackage#getConstraint()
 * @model kind="class" abstract="true"
 * @generated
 */
public abstract class Constraint extends EObjectImpl implements Element, Predicate {

	/**
	 * @model kind="operation"
	 * @generated NOT
	 */
	public abstract boolean isTrue();

	/**
	 * @model kind="operation"
	 * @generated NOT
	 */
	public abstract boolean isFalse();

	/* ---------------------------------------------------------------- *
	 * GENERATED CODE.                                                  *
	 * Do not edit below this line. If you need to edit, move it above  *
	 * this line and change the '@generated'-tag to '@generated NOT'.   *
	 * ---------------------------------------------------------------- */	

	/**
	 * The default value of the '{@link #isInferred() <em>Inferred</em>}' attribute.
	 * @see #isInferred()
	 * @generated
	 * @ordered
	 */
	protected static final boolean INFERRED_EDEFAULT = false;
	
	/**
	 * The cached value of the '{@link #isInferred() <em>Inferred</em>}' attribute.
	 * @see #isInferred()
	 * @generated
	 * @ordered
	 */
	protected boolean inferred = INFERRED_EDEFAULT;

	/**
	 * @generated
	 */
	public Constraint() {
		super();
	}

	/**
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return IotaPackage.Literals.CONSTRAINT;
	}

	/**
	 * Returns the value of the '<em><b>Clause</b></em>' container reference.
	 * It is bidirectional and its opposite is '{@link org.eclipse.iota.model.Clause#getConstraints <em>Constraints</em>}'.
	 * @return the value of the '<em>Clause</em>' container reference.
	 * @see #setClause(Clause)
	 * @see org.eclipse.iota.IotaPackage#getConstraint_Clause()
	 * @see org.eclipse.iota.model.Clause#getConstraints
	 * @model opposite="constraints" transient="false"
	 * @generated
	 */
	public Clause getClause() {
		if (eContainerFeatureID() != IotaPackage.CONSTRAINT__CLAUSE) return null;
		return (Clause)eContainer();
	}

	/**
	 * @generated
	 */
	public NotificationChain basicSetClause(Clause newClause, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newClause, IotaPackage.CONSTRAINT__CLAUSE, msgs);
		return msgs;
	}

	/**
	 * Sets the value of the '{@link org.eclipse.iota.model.Constraint#getClause <em>Clause</em>}' container reference.
	 * @param value the new value of the '<em>Clause</em>' container reference.
	 * @see #getClause()
	 * @generated
	 */
	public void setClause(Clause newClause) {
		if (newClause != eInternalContainer() || (eContainerFeatureID() != IotaPackage.CONSTRAINT__CLAUSE && newClause != null)) {
			if (EcoreUtil.isAncestor(this, newClause))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newClause != null)
				msgs = ((InternalEObject)newClause).eInverseAdd(this, IotaPackage.CLAUSE__CONSTRAINTS, Clause.class, msgs);
			msgs = basicSetClause(newClause, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IotaPackage.CONSTRAINT__CLAUSE, newClause, newClause));
	}

	/**
	 * Returns the value of the '<em><b>Inferred</b></em>' attribute.
	 * The default value is <code>"false"</code>.
	 * @return the value of the '<em>Inferred</em>' attribute.
	 * @see #setInferred(boolean)
	 * @see org.eclipse.iota.IotaPackage#getConstraint_Inferred()
	 * @model default="false"
	 * @generated
	 */
	public boolean isInferred() {
		return inferred;
	}

	/**
	 * Sets the value of the '{@link org.eclipse.iota.model.Constraint#isInferred <em>Inferred</em>}' attribute.
	 * @param value the new value of the '<em>Inferred</em>' attribute.
	 * @see #isInferred()
	 * @generated
	 */
	public void setInferred(boolean newInferred) {
		boolean oldInferred = inferred;
		inferred = newInferred;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, IotaPackage.CONSTRAINT__INFERRED, oldInferred, inferred));
	}

	/**
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetClause((Clause)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				return basicSetClause(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				return eInternalContainer().eInverseRemove(this, IotaPackage.CLAUSE__CONSTRAINTS, Clause.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				return getClause();
			case IotaPackage.CONSTRAINT__INFERRED:
				return isInferred();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				setClause((Clause)newValue);
				return;
			case IotaPackage.CONSTRAINT__INFERRED:
				setInferred((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				setClause((Clause)null);
				return;
			case IotaPackage.CONSTRAINT__INFERRED:
				setInferred(INFERRED_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case IotaPackage.CONSTRAINT__CLAUSE:
				return getClause() != null;
			case IotaPackage.CONSTRAINT__INFERRED:
				return inferred != INFERRED_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (inferred: ");
		result.append(inferred);
		result.append(')');
		return result.toString();
	}

}
